/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author Administrator
 */
public class TopUserScene extends Scene {
    
    private static final int TOP_RICH = 0;
    private static final int TOP_LEVEL = 1;
    private int topUserType;
    private Image topBarImage;
    private Image bottomBarImage;
    private int numberInfos;
    
    public TopUserScene(MainCanvas parent) {
        super(parent);
        initValue();
        initObject();
    }
    
    private void initValue() {
        numberInfos = gameData.getNumberTopUserInfo();
        topUserType = gameData.getTopUserType();
    }
    
    private void initObject() {
        try {
            topBarImage = library.getTopBarImage();
            bottomBarImage = library.getBottomBarImage();
        } catch (IOException ex) {
        }
    }

//------------------------------------------------------------------------------
    public void setListSubMenu() {
        subMenu.setList(null);
    }
    
    public void doLoop() {
    }
    //--------------------------------------------------------------------------

    public void paintComponents(Graphics g) {
        paintBarMenu(g);
        if (topUserType == TOP_RICH) {
            paintTopRich(g);
        } else {
            paintTopLevel(g);
        }
    }
    
    private void paintTopRich(Graphics g) {
        int topList = topScreen + topBarImage.getHeight();
        int anchorRight = (screenMode == SCREEN_PORTRAIT ? canvasWidth - 50 : canvasWidth - 80);
        PiPoDesigner.drawString(g, "TT", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_YELOW, leftScreen + 10, topList);
        PiPoDesigner.drawString(g, "Tên", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_YELOW, leftScreen + 40, topList);
        PiPoDesigner.drawString(g, "Tiền", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_YELOW, anchorRight, topList);
        topList += 20;
        g.setClip(0, topList, canvasWidth, canvasHeight - 70);
        for (int i = 0; i < numberInfos; i++) {
            PlayerInfo info = gameData.listInfos[i];
            PiPoDesigner.drawString(g, String.valueOf(i + 1), PiPoDesigner.COLOR_BLACK,
                    PiPoDesigner.COLOR_WHITE, leftScreen + 15, topList);
            PiPoDesigner.drawString(g, info.getName(), PiPoDesigner.COLOR_BLACK,
                    PiPoDesigner.COLOR_WHITE, leftScreen + 40, topList);
            PiPoDesigner.drawString(g, String.valueOf(info.getMoney()), PiPoDesigner.COLOR_BLACK,
                    PiPoDesigner.COLOR_WHITE, anchorRight, topList);
            topList += 20;
        }
        g.setClip(0, 0, canvasWidth, canvasHeight);
    }
    
    private void paintTopLevel(Graphics g) {
        int topList = topScreen + topBarImage.getHeight();
        int anchorRight = (screenMode == SCREEN_PORTRAIT ? canvasWidth - 30 : canvasWidth - 80);
        PiPoDesigner.drawString(g, "TT", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_YELOW, leftScreen + 10, topList);
        PiPoDesigner.drawString(g, "Tên", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_YELOW, leftScreen + 40, topList);
        PiPoDesigner.drawString(g, "Level", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_YELOW, anchorRight, topList);
        topList += 20;
        g.setClip(0, topList, canvasWidth, canvasHeight - 70);
        for (int i = 0; i < numberInfos; i++) {
            PlayerInfo info = gameData.listInfos[i];
            PiPoDesigner.drawString(g, String.valueOf(i + 1), PiPoDesigner.COLOR_BLACK,
                    PiPoDesigner.COLOR_WHITE, leftScreen + 15, topList);
            PiPoDesigner.drawString(g, info.getName(), PiPoDesigner.COLOR_BLACK,
                    PiPoDesigner.COLOR_WHITE, leftScreen + 40, topList);
            PiPoDesigner.drawString(g, String.valueOf(info.getLevel()), PiPoDesigner.COLOR_BLACK,
                    PiPoDesigner.COLOR_WHITE, anchorRight, topList);
            topList += 20;
        }
        g.setClip(0, 0, canvasWidth, canvasHeight);
        
    }
    
    protected void paintBarMenu(Graphics g) {
        
        g.drawImage(topBarImage, leftScreen, topScreen, 0);
        g.drawImage(bottomBarImage, leftScreen, canvasHeight - bottomBarImage.getHeight(), 0);
        if (topUserType == TOP_RICH) {
            PiPoDesigner.drawString(g, "Top đại gia", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_YELOW,
                    canvasWidth / 2 - PiPoDesigner.stringWidth("top dai gia") / 2, topScreen + 5);
        } else {
            PiPoDesigner.drawString(g, "Top cao thủ", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_YELOW,
                    canvasWidth / 2 - PiPoDesigner.stringWidth("top cao thu") / 2, topScreen + 5);
        }
        PiPoDesigner.drawString(g, "Đóng", PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_WHITE, canvasWidth - 40, canvasHeight - 25);
    }
    //-------------------------------------------------------------------------

    public void doKeyLeft() {
    }
    
    public void doKeyRight() {
    }
    
    public void doKeyPound() {
    }
    
    protected void doKeyUpRemain() {
    }
    
    protected void doKeyDownRemain() {
    }
    
    protected void doSoftKeyLeftRemain() {
    }
    
    protected void doSoftKeyRightRemain() {
        showChooseGame();
    }
    
    protected void reponseQuestion(int result) {
    }
    
    protected void doKeyCenterRemain() {
    }
    
    public void inputKeyCode(int key) {
    }
    
    protected void touchPressedRemain(int x, int y) {
    }
    
    public void doTouchReleased(int x, int y) {
    }
    
    public void doTouchDraged(int x, int y) {
    }
    
    public void processMessage(String[] part) {
        super.processMessage(part);
    }
    
    protected void doSubMenu() {
    }
    //-------------------------------------------------------------------------

    public void dispose() {
//        backgroundImage = null;
        bottomBarImage = null;
        topBarImage = null;
        gameData.disposeListInfos();
        super.dispose();
    }
}
